package com.anti.modular.sys.dict.controller;

import com.anti.commom.annotation.BusinessLog;
import com.anti.commom.annotation.Permission;
import com.anti.commom.api.Result;
import com.anti.commom.enums.LogAnnotionOpTypeEnum;
import com.anti.jdbc.support.page.PageParam;
import com.anti.modular.sys.dict.param.SysDictDataParam;
import com.anti.modular.sys.dict.service.SysDictDataService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 系统字典值控制器
 */
@RestController
@RequestMapping("sysDictData")
public class SysDictDataController {

    @Resource
    private SysDictDataService sysDictDataService;

    /**
     * 查询系统字典值
     */
    @Permission
    @GetMapping("page")
    @BusinessLog(title = "系统字典值_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result page(PageParam pageParam,SysDictDataParam sysDictDataParam) {
        return Result.data(sysDictDataService.page(pageParam,sysDictDataParam));
    }

    /**
     * 某个字典类型下所有的字典
     */
    @Permission
    @GetMapping("list")
    @BusinessLog(title = "系统字典值_列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result list(@Validated(SysDictDataParam.list.class) SysDictDataParam sysDictDataParam) {
        return Result.data(sysDictDataService.list(sysDictDataParam));
    }

    /**
     * 查看系统字典值
     *
     * @author xuyuxiang
     * @date 2020/3/31 20:51
     */
    @Permission
    @GetMapping("detail")
    @BusinessLog(title = "系统字典值_查看", opType = LogAnnotionOpTypeEnum.DETAIL)
    public Result detail(@Validated(SysDictDataParam.detail.class) SysDictDataParam sysDictDataParam) {
        return Result.data(sysDictDataService.detail(sysDictDataParam));
    }

    /**
     * 添加系统字典值
     */
    @Permission
    @PostMapping("add")
    @BusinessLog(title = "系统字典值_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public Result add(@RequestBody @Validated(SysDictDataParam.add.class) SysDictDataParam sysDictDataParam) {
        sysDictDataService.add(sysDictDataParam);
        return Result.success("字典值增加成功");
    }

    /**
     * 删除系统字典值
     */
    @Permission
    @PostMapping("delete")
    @BusinessLog(title = "系统字典值_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public Result delete(@RequestBody @Validated(SysDictDataParam.delete.class) SysDictDataParam sysDictDataParam) {
        sysDictDataService.delete(sysDictDataParam);
        return Result.success("删除成功");
    }

    /**
     * 编辑系统字典值
     */
    @Permission
    @PostMapping("edit")
    @BusinessLog(title = "系统字典值_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result edit(@RequestBody @Validated(SysDictDataParam.edit.class) SysDictDataParam sysDictDataParam) {
        sysDictDataService.edit(sysDictDataParam);
        return Result.success("修改成功");
    }

    /**
     * 修改状态
     */
    @Permission
    @PostMapping("changeStatus")
    @BusinessLog(title = "系统字典值_修改状态", opType = LogAnnotionOpTypeEnum.CHANGE_STATUS)
    public Result changeStatus(@RequestBody @Validated(SysDictDataParam.changeStatus.class) SysDictDataParam sysDictDataParam) {
        sysDictDataService.updateChangeStatus(sysDictDataParam);
        return Result.success("状态修改成功");
    }

}
